using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VPJKUNDE
    {
        public DataRow Convert2PJKUNDE(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryPJKUNDE(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["PKDMANDANT"] = " ".PadRight(2 ); 
         dwReturn["PKDPROJNR"] = " ".PadRight(5 ); 
         dwReturn["PKDKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["PKDADRSL"] = " ".PadRight(8 ); 
         dwReturn["PKDANSPNA"] = " ".PadRight(8 ); 
         dwReturn["PKDVORH"] = " ".PadRight(1 ); 
         dwReturn["PKDSTATUS"] = " ".PadRight(1 ); 
         dwReturn["PKDUNKLARGRD"] = " ".PadRight(2 ); 
         dwReturn["PKDSELLFDNR"] = " ".PadRight(0 ); 
         dwReturn["PKDANREDE"] = " ".PadRight(1 ); 
         dwReturn["PKDNAME1"] = " ".PadRight(25 ); 
         dwReturn["PKDNAME2"] = " ".PadRight(25 ); 
         dwReturn["PKDSTRASSE"] = " ".PadRight(25 ); 
         dwReturn["PKDZUSATZ"] = " ".PadRight(25 ); 
         dwReturn["PKDLKZ"] = " ".PadRight(3 ); 
         dwReturn["PKDPLZ"] = " ".PadRight(7 ); 
         dwReturn["PKDORT"] = " ".PadRight(25 ); 
         dwReturn["PKDPOSTFACH"] = " ".PadRight(15 ); 
         dwReturn["PKDSACHBEARB"] = " ".PadRight(8 ); 
         dwReturn["PKDVERTRETER"] = " ".PadRight(8 ); 
         dwReturn["PKDSTDVERANTW"] = " ".PadRight(8 ); 
         dwReturn["PKDABZUGSKENNZ"] = " ".PadRight(1 ); 
         dwReturn["PKDABZUGSDATUM"] = " ".PadRight(0 ); 
         dwReturn["PKDANZTAET"] = " ".PadRight(0 ); 
         dwReturn["PKDANZTAETUEBW"] = " ".PadRight(0 ); 
         dwReturn["PKDANZTAETERL"] = " ".PadRight(0 ); 
         dwReturn["PKDNEUBEN"] = " ".PadRight(8 ); 
         dwReturn["PKDNEUDAT"] = " ".PadRight(0 ); 
         dwReturn["PKDAENDBEN"] = " ".PadRight(8 ); 
         dwReturn["PKDAENDDAT"] = " ".PadRight(0 ); 
         dwReturn["PKDAENDZL"] = " ".PadRight(0 ); 
         dwReturn["PKDTELEFON"] = " ".PadRight(20 ); 
         dwReturn["PKDTELEFAX"] = " ".PadRight(20 ); 
         dwReturn["PKDSPRKZ"] = " ".PadRight(1 ); 
         dwReturn["PKDFILLER"] = " ".PadRight(70 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapPJKUNDE(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SavePJKUNDE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryPJKUNDE(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapPJKUNDE(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertPJKUNDE(dwLocal, ITXDBVERSION);
            }
            UpdatePJKUNDE(dwLocal);
        }
        public void InsertPJKUNDE(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO PJKUNDE(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryPJKUNDE(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM PJKUNDE WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM PJKUNDE  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "PJKUNDE";
            Return = Result;
            return Return;
        }
        public void DeletePJKUNDE(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM PJKUNDE   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdatePJKUNDE(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE PJKUNDE SET "
                    +"PKDMANDANT= :PKDMANDANT,"
                    +"PKDPROJNR= :PKDPROJNR,"
                    +"PKDKUNDNR= :PKDKUNDNR,"
                    +"PKDADRSL= :PKDADRSL,"
                    +"PKDANSPNA= :PKDANSPNA,"
                    +"PKDVORH= :PKDVORH,"
                    +"PKDSTATUS= :PKDSTATUS,"
                    +"PKDUNKLARGRD= :PKDUNKLARGRD,"
                    +"PKDSELLFDNR= :PKDSELLFDNR,"
                    +"PKDANREDE= :PKDANREDE,"
                    +"PKDNAME1= :PKDNAME1,"
                    +"PKDNAME2= :PKDNAME2,"
                    +"PKDSTRASSE= :PKDSTRASSE,"
                    +"PKDZUSATZ= :PKDZUSATZ,"
                    +"PKDLKZ= :PKDLKZ,"
                    +"PKDPLZ= :PKDPLZ,"
                    +"PKDORT= :PKDORT,"
                    +"PKDPOSTFACH= :PKDPOSTFACH,"
                    +"PKDSACHBEARB= :PKDSACHBEARB,"
                    +"PKDVERTRETER= :PKDVERTRETER,"
                    +"PKDSTDVERANTW= :PKDSTDVERANTW,"
                    +"PKDABZUGSKENNZ= :PKDABZUGSKENNZ,"
                    +"PKDABZUGSDATUM= :PKDABZUGSDATUM,"
                    +"PKDANZTAET= :PKDANZTAET,"
                    +"PKDANZTAETUEBW= :PKDANZTAETUEBW,"
                    +"PKDANZTAETERL= :PKDANZTAETERL,"
                    +"PKDNEUBEN= :PKDNEUBEN,"
                    +"PKDNEUDAT= :PKDNEUDAT,"
                    +"PKDAENDBEN= :PKDAENDBEN,"
                    +"PKDAENDDAT= :PKDAENDDAT,"
                    +"PKDAENDZL= :PKDAENDZL,"
                    +"PKDTELEFON= :PKDTELEFON,"
                    +"PKDTELEFAX= :PKDTELEFAX,"
                    +"PKDSPRKZ= :PKDSPRKZ,"
                    +"PKDFILLER= :PKDFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("PKDMANDANT", OracleType.NVarChar).Value = dwData["PKDMANDANT"].ToString(); 
          or1.Parameters.Add("PKDPROJNR", OracleType.NVarChar).Value = dwData["PKDPROJNR"].ToString(); 
          or1.Parameters.Add("PKDKUNDNR", OracleType.NVarChar).Value = dwData["PKDKUNDNR"].ToString(); 
          or1.Parameters.Add("PKDADRSL", OracleType.NVarChar).Value = dwData["PKDADRSL"].ToString(); 
          or1.Parameters.Add("PKDANSPNA", OracleType.NVarChar).Value = dwData["PKDANSPNA"].ToString(); 
          or1.Parameters.Add("PKDVORH", OracleType.NVarChar).Value = dwData["PKDVORH"].ToString(); 
          or1.Parameters.Add("PKDSTATUS", OracleType.NVarChar).Value = dwData["PKDSTATUS"].ToString(); 
          or1.Parameters.Add("PKDUNKLARGRD", OracleType.NVarChar).Value = dwData["PKDUNKLARGRD"].ToString(); 
          or1.Parameters.Add("PKDSELLFDNR", OracleType.NVarChar).Value = dwData["PKDSELLFDNR"].ToString(); 
          or1.Parameters.Add("PKDANREDE", OracleType.NVarChar).Value = dwData["PKDANREDE"].ToString(); 
          or1.Parameters.Add("PKDNAME1", OracleType.NVarChar).Value = dwData["PKDNAME1"].ToString(); 
          or1.Parameters.Add("PKDNAME2", OracleType.NVarChar).Value = dwData["PKDNAME2"].ToString(); 
          or1.Parameters.Add("PKDSTRASSE", OracleType.NVarChar).Value = dwData["PKDSTRASSE"].ToString(); 
          or1.Parameters.Add("PKDZUSATZ", OracleType.NVarChar).Value = dwData["PKDZUSATZ"].ToString(); 
          or1.Parameters.Add("PKDLKZ", OracleType.NVarChar).Value = dwData["PKDLKZ"].ToString(); 
          or1.Parameters.Add("PKDPLZ", OracleType.NVarChar).Value = dwData["PKDPLZ"].ToString(); 
          or1.Parameters.Add("PKDORT", OracleType.NVarChar).Value = dwData["PKDORT"].ToString(); 
          or1.Parameters.Add("PKDPOSTFACH", OracleType.NVarChar).Value = dwData["PKDPOSTFACH"].ToString(); 
          or1.Parameters.Add("PKDSACHBEARB", OracleType.NVarChar).Value = dwData["PKDSACHBEARB"].ToString(); 
          or1.Parameters.Add("PKDVERTRETER", OracleType.NVarChar).Value = dwData["PKDVERTRETER"].ToString(); 
          or1.Parameters.Add("PKDSTDVERANTW", OracleType.NVarChar).Value = dwData["PKDSTDVERANTW"].ToString(); 
          or1.Parameters.Add("PKDABZUGSKENNZ", OracleType.NVarChar).Value = dwData["PKDABZUGSKENNZ"].ToString(); 
          or1.Parameters.Add("PKDABZUGSDATUM", OracleType.NVarChar).Value = dwData["PKDABZUGSDATUM"].ToString(); 
          or1.Parameters.Add("PKDANZTAET", OracleType.NVarChar).Value = dwData["PKDANZTAET"].ToString(); 
          or1.Parameters.Add("PKDANZTAETUEBW", OracleType.NVarChar).Value = dwData["PKDANZTAETUEBW"].ToString(); 
          or1.Parameters.Add("PKDANZTAETERL", OracleType.NVarChar).Value = dwData["PKDANZTAETERL"].ToString(); 
          or1.Parameters.Add("PKDNEUBEN", OracleType.NVarChar).Value = dwData["PKDNEUBEN"].ToString(); 
          or1.Parameters.Add("PKDNEUDAT", OracleType.NVarChar).Value = dwData["PKDNEUDAT"].ToString(); 
          or1.Parameters.Add("PKDAENDBEN", OracleType.NVarChar).Value = dwData["PKDAENDBEN"].ToString(); 
          or1.Parameters.Add("PKDAENDDAT", OracleType.NVarChar).Value = dwData["PKDAENDDAT"].ToString(); 
          or1.Parameters.Add("PKDAENDZL", OracleType.NVarChar).Value = dwData["PKDAENDZL"].ToString(); 
          or1.Parameters.Add("PKDTELEFON", OracleType.NVarChar).Value = dwData["PKDTELEFON"].ToString(); 
          or1.Parameters.Add("PKDTELEFAX", OracleType.NVarChar).Value = dwData["PKDTELEFAX"].ToString(); 
          or1.Parameters.Add("PKDSPRKZ", OracleType.NVarChar).Value = dwData["PKDSPRKZ"].ToString(); 
          or1.Parameters.Add("PKDFILLER", OracleType.NVarChar).Value = dwData["PKDFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
